#import "UmsPayPlugin.h"
#import "UMSPPPayUnifyPayPlugin.h"
#import "WXApi.h"

@implementation UmsPayPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    FlutterMethodChannel* channel = [FlutterMethodChannel
                                     methodChannelWithName:@"ums_pay"
                                     binaryMessenger:[registrar messenger]];
    UmsPayPlugin* instance = [[UmsPayPlugin alloc] init];
    [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    if ([@"getPlatformVersion" isEqualToString:call.method]) {
        result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
    } else if ([@"pay" isEqualToString:call.method]) {
        [self handlePay:call result:result];
        
    } else {
        result(FlutterMethodNotImplemented);
    }
}

- (void)handlePay:(FlutterMethodCall *)call result:(FlutterResult)result {
    NSString *channel = call.arguments[@"channel"];
    NSString *data = call.arguments[@"data"];
//    result(@{@"msg": @"msg", @"code": @"resultCode", @"data": @"resultInfo"});
//    return;
    [UMSPPPayUnifyPayPlugin payWithPayChannel:channel payData:data callbackBlock:^(NSString *resultCode, NSString *resultInfo) {
        result(@{@"msg": @"msg", @"code": resultCode, @"data": resultInfo});
    }];
    
}

@end
